<?php
header("Content-type:text/html;charset=utf-8");
//获取用户提交的数据
if($_POST){
	
	//pdo链接数据库
	$server = 'localhost';
	$user = 'root';
	$psw = 'root';
	$db = 'qq';

	
	try{


		//链接数据库
		$conn = new PDO("mysql:host=$server;dbname=$db",$user,$psw);
		$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        //把数据写入数据库保存
	    $sql = "insert into user values (NULL,'$_POST[username]',$_POST[password])";
	    $conn->exec($sql);
	    
	    //添加成功跳转到onload页面
	    header('Location:index.php');

	}catch(PDOException $e){
        echo $sql . "<br>" . $e->getMessage();
	}


}else{
	include 'regist.html';
}



